<!--
 - Author : 003.
 - Date   : 2018/9/25.
 - File   : 新建
 -->

<template>
  <div class="wrapper publish">
    <b-header></b-header>
    <div class="main-wrapper isno-left-bar">
      <div class="main-content">
        <div class="page">
          <div style="text-align: left;">
            <div class="btn_file" style="margin-bottom:10px;">
              <div class="file_box file_box1">
                <i class="iconfont icon-Excel"></i>
                <input
                  type="file"
                  id="excel-file"
                  name="upload"
                  class="file-btn"
                  @change="exportExcel2"
                >导入
              </div>
            </div>
            <div class="flex" v-for="(item, index) in orderList" :key="index">
              <div>{{item.productName}}</div>
              <div><img :src="item.mainImg" alt="" style="width:400px"></div>
              <div>
                <p>【原价】 {{item.productPrice}}元</p>
                <p v-if="item.leftCount !== '0'">【券后价】 元</p>
                <p>【定金】 元，下定立减 元~</p>
                <p>【返利】{{item.commission.toFixed(2) + '元'}}</p>
                <p>【赠品】 ~</p>
                <p> -------------------</p>
                <p>復製这条{{item.commissionPw?item.commissionPw:item.Passwords}}</p>
                <p>进入【Tao宝】即可抢购</p>
              </div>
              <p> --------------------------------------</p>
              <div>
                <p>提示</p>
                <p>【优惠券】{{item.couponPrice}}</p>
                <p>【使用期】{{item.startTime + '~' + item.endTime}}</p>
                <p>【商品详情页链接地址】{{item.detailLink}}</p>
                <p>【店铺】{{item.shop}}</p>
                <p :class="[item.leftCount === '0' ?'red':'']">【优惠券剩余量】{{item.leftCount}}</p>
              </div>
              <br/>
              <br/>
              <br/>
            </div>          
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { apiSource, get } from "../../travel-api"
import * as axios from 'axios'
import XLSX from "xlsx";
import config from "../../config"

export default {
  data() {
    return {
      member1: {},
      priceCount: '',
      endTime: [],
      productId: "",
      orderList: [],
      exportList: []
    }
  },
  watch: {
  },
  mounted() {
  },
  methods: {
    /**
     * 客户信息导入表格
     */
    exportExcel2(e) {
      var self = this
      var files = e.target.files
      // var rABS = false
      var fileReader = new FileReader()
      fileReader.onload = function(ev) {
        try {
          var data = ev.target.result,
            workbook = XLSX.read(data, {
              type: "binary"
            }), // 以二进制流方式读取得到整份excel表格对象
            persons = [] // 存储获取到的数据
        } catch (e) {
          console.error(e)
          self.$message.error("文件类型不正确")
          return
        }
        var exportList = JSON.parse(
          JSON.stringify(
            XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]])
          )
        )
        var jsonList = []
        if (exportList.length > 0) {
          jsonList = exportList.map((item, index) => {
            return {
              productId: item["商品id"],
              productName: item["商品名称"],
              mainImg: item["商品主图"],
              productPrice: item["商品价格(单位：元)"],
              commission: (item["佣金"]* 0.45),
              commissionPw: item["优惠券淘口令(30天内有效)"],
              Passwords: item["淘口令(30天内有效)"],
              leftCount: item["优惠券剩余量"],
              detailLink: item["商品详情页链接地址"],
              couponLink: item["优惠券链接"],
              couponSum: item["优惠券总量"],
              couponRest: item["优惠券剩余量"],
              couponPrice: item["优惠券面额"],
              startTime: item["优惠券开始时间"],
              endTime: item["优惠券结束时间"],
              shop: item["店铺名称"]
            }
          })
        }
        console.log("jsonList", jsonList, exportList)
        self.orderList = jsonList
      }
      // 以二进制方式打开文件
      fileReader.readAsBinaryString(files[0])
      // console.log('导入表格',e)
      e.target.value = ""
    },
    /**
     * 计算总数
     */
    countResult(list) {
      console.log("member", list)
    },
    /**
     * 求最高价全票
     */
    filterDefault() {
      let arr = this.allTravelList.map(v => {
        return {
          commission: v.commission,
          Passwords: v.Passwords,
          couponSum: v.priceInfo[0].unitprice
        }
      })
      let index = 0
      console.log("最高价全票arr", arr, this.allTravelList)
      var num = arr[0].couponSum
      for (var i = 0; i < arr.length; i++) {
        if (arr[i].couponSum > num) {
          num = arr[i].couponSum
          index = i
        }
      }
      return {
        commission: arr[index].commission,
        Passwords: arr[index].Passwords,
        ruleName: "默认",
        couponSum: arr[index].couponSum,
        couponPrice: ""
      }
    },
    /**
     * 入园日期格式化
     */
    inDateVal(val) {
      this.inDate = val
      this.getTravelOrderItem(val)
    },
    /**
     * 计划到达时间格式化
     */
    arriveTimeVal(val) {
      this.arriveTime = val
    },
    /**
     * 返回首页
     * @date 2019-06-10
     */
    back() {
      this.$router.push({ path: "/booking/index" })
    },
    double(val) {
      if (val < 10) {
        return "0" + val
      } else {
        return val.toString()
      }
    }
  }
}
</script>

<style lang="less" scoped>
@import "../../assets/less/booking.less";
.page {
  &-title {
    .el-form-item {
      margin-bottom: 0;
    }
    .btn_file {
      // padding-left: 58px;
      .el-button {
        width: 120px;
        height: 45px;
        span {
          vertical-align: middle;
          i {
            margin-right: 5px;
            vertical-align: middle;
          }
        }
      }
    }
  }
  .flex_check_ct {
    display: inline-block;
    margin-right: 20px;
    // width: 80px;
    // flex: 1;
  }
  .el-form {
    height: 100%;
  }
  .select {
    padding: 0.3rem 1.3rem 0.3rem 0.3rem;
    background: #fff;
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    .ellipsis {
      display: -webkit-box;
      overflow: hidden;
      text-overflow: ellipsis;
      word-break: break-all;
      -webkit-box-orient: vertical !important;
      -webkit-line-clamp: 1;
    }
    &_title {
      min-width: 200px;
      font-size: 12px;
    }
    i {
      top: 2px;
    }
    ul {
      top: 37px;
    }
  }
  .page-content {
    padding-bottom: 130px;
  }
  .cus_form {
    margin-bottom: 0px;
    margin-left: -130px;
  }
  .table_wrap {
    overflow-x: auto;
  }
  .table-order {
    > thead > tr > th {
      box-sizing: border-box;
    }
    > tbody > tr:nth-of-type(odd) {
      background-color: #fff;
    }
    > tbody > tr:nth-of-type(even) {
      background-color: #eeecec;
    }
    .el-form-item {
      margin-bottom: 0;
    }
    .ct {
      display: inline-block;
      min-width: 40px;
      &.empty{
        background: red;
      }
      .zhutu{
        width: 100px;
      }
    }
    .el-input {
      height: 36px;
      input {
        height: 100%;
      }
    }
    .el-dropdown {
      font-size: 1.1rem;
    }
  }
  .table-order-hover {
    > tbody > tr:hover {
      background-color: rgb(241, 241, 241);
    }
  }
  .add-order {
    margin: 1rem auto;
    color: #37b0eb;
    font-size: 25px;
    text-align: center;
    cursor: pointer;
    .el-button--large {
      padding: 12px 60px;
    }
  }
  .file_box {
    display: inline-block;
    position: relative;
    font-weight: 500;
    height: 45px;
    width: 120px;
    text-align: center;
    font-size: 14px;
    line-height: 45px;
    border-radius: 4px;
    overflow: hidden;
    color: #1eb1b1;
    background: #e0f7f7;
    border: 1px solid #1eb1b1;
    cursor: pointer;
    vertical-align: middle;
    i:hover {
      color: #fff;
    }
    &:hover {
      color: #fff;
      background-color: #1eb1b1;
      border-color: #1eb1b1;
      cursor: pointer;
    }
  }
  .file_box1 {
    margin: 0 20px 0 0px;
    i {
      font-size: 26px;
      color: #1b8a4e;
      vertical-align: middle;
      margin-right: 5px;
    }
  }
  .file_box2 {
    a {
      display: block;
      width: 100%;
      height: 100%;
      &:hover {
        color: #fff;
      }
    }
  }
  .file-btn {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    outline: none;
    background-color: transparent;
    filter: alpha(opacity=0);
    -moz-opacity: 0;
    -khtml-opacity: 0;
    opacity: 0;
    cursor: pointer;
  }
}
.el-dropdown-menu {
  max-height: 300px;
  overflow-y: auto;
}
.el-form-item__error {
  top: 0;
  height: 17px;
}
.el-dropdown {
  width: 100%;
  &-link {
    width: 90%;
    line-height: 40px;
    i {
      position: absolute;
      top: 13px;
      right: 0;
    }
  }
}
.ellipsis {
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
  -webkit-box-orient: vertical !important;
  -webkit-line-clamp: 1;
}
.red{
  color: red;
}
</style>
